package com.ydd.controller.user;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageHelper;
import com.ydd.dto.AdvposDTO;
import com.ydd.entity.Advimg;
import com.ydd.entity.Advpos;
import com.ydd.mapper.AdvimgMapper;
import com.ydd.result.PageResult;
import com.ydd.result.Result;
import com.ydd.service.IAdvimgService;
import com.ydd.service.IAdvposService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hgz
 * @since 2023-05-30
 */
@RestController
@RequestMapping("/admin/ydd_advpos")
@Slf4j
public class AdvposController {

    @Autowired
    private IAdvposService iAdvposService;
    @Autowired
    private AdvimgMapper advimgMapper;

    /**
     * 广告位接口分页
     * @param advposDTO
     * @return
     */
    @ApiOperation("广告位接口分页")
    @GetMapping("/list")
    public Result<Map<String,Object>> list(AdvposDTO advposDTO){
        log.info("广告位接口分页：{}",advposDTO);

        Map<String, Object> map = iAdvposService.selectPage(advposDTO);
        return Result.success(map);
    }

    /**
     * 广告管理修改接口
     * @param advpos
     * @return
     */
    @ApiOperation("广告管理修改接口")
    @PostMapping("/update")
    public Result upd(@RequestBody Advpos advpos){
        log.info("广告管理修改接口：{}",advpos);

        iAdvposService.upda(advpos);

        return Result.success();
    }

    /**
     * 广告位删除接口
     * @param id
     * @return
     */
    @ApiOperation("广告位删除接口")
    @GetMapping("/del")
    public Result del(@RequestParam Integer id){

        log.info("广告位删除接口：{}",id);
        iAdvposService.del(id);

        return Result.success();
    }

    /**
     * 广告位添加接口
     * @param advpos
     * @return
     */
    @ApiOperation("广告位添加接口")
    @PostMapping("/add")
    public Result add(@RequestBody Advpos advpos){
        log.info("广告位添加接口:{}",advpos);
        iAdvposService.add(advpos);
        return Result.success();
    }

    /**
     * 根据id回显数据
     * @param id
     * @return
     */
    @ApiOperation("根据id回显数据")
    @GetMapping("/rowInfo")
    public Result<Advpos> rowInfo(@RequestParam Integer id){

        log.info("根据id回显数据：{}",id);

       Advpos advpos = iAdvposService.rowInfo(id);

        return Result.success(advpos);
    }
    @GetMapping("/all")
    public Result<List<Advpos>> all(){

        List<Advpos> adv = iAdvposService.all();
        return Result.success(adv);
        }


}
